package laravel_generator;

import org.reflections.Reflections;
import org.reflections.scanners.ResourcesScanner;
import org.reflections.scanners.SubTypesScanner;
import org.reflections.util.ClasspathHelper;
import org.reflections.util.ConfigurationBuilder;
import org.reflections.util.FilterBuilder;

import java.util.LinkedList;
import java.util.List;
import java.util.Set;

/**
 * Created by nuno-rafael-figueiredo on 04-05-2014.
 */
public class ModelClassLoader {
    public static final List<ClassLoader> classLoadersList = new LinkedList<ClassLoader>(){{
        add(ClasspathHelper.contextClassLoader());
        add(ClasspathHelper.staticClassLoader());
    }};

    public static final FilterBuilder FILTER_BUILDER = new FilterBuilder()
            .include(FilterBuilder.prefix("bamp.entities"));

    public static final Reflections REFLECTIONS = new Reflections(new ConfigurationBuilder()
            .setScanners(new SubTypesScanner(false /* don't exclude Object.class */), new ResourcesScanner())
            .setUrls(ClasspathHelper.forClassLoader(classLoadersList.toArray(new ClassLoader[classLoadersList.size()])))
            .filterInputsBy(FILTER_BUILDER));

    public static final Set<Class<?>> ALL_CLASSES =
            REFLECTIONS.getSubTypesOf(Object.class);
}
